var vr;
$(function(){ 
	
	$("#leaveMessageForm").bind("submit", submitMsg);
	vr = $("#leaveMessageForm").validate({
		rules: {
			lm_email: {
				required: true,
				email: true
			},
			lm_content: {
				required: true
			}
		},
		messages: {
			lm_email: {
				required: iPadLang.emailRequired,
				email: iPadLang.emailError
			},
			lm_content: {
				required: iPadLang.leaveMessageRequired
			}
		},
		showErrors: function(errorMap, errorList) {
            var msg = "";
            jQuery.each(errorList, function(i, v) {
                msg += (v.message + "\r\n");  
            });
            if (msg != ""){ 
                alert(msg);
            }
        },
        onfocusout: false,
        onkeyup :false
	});
});


function submitMsg(){
	if(!vr.checkForm())return false;
	try{
		var email =  $("#leaveMessageForm input").eq(0).val();
		var content = $("#leaveMessageForm textarea").val();
		info("[leaveMessage][submitMsg] email:"+email+",textarea"+content);
		commitLeaveMessage(email, content, success);
	}catch(e){
		error(e);
		return false;
	}
	return false;
}

function success(){
	alert(iPadLang.submitSuccess);
	$("#leaveMessageForm textarea").val("");
}


